import time

from selenium.webdriver.common.by import By

from common.untils import Lunta
class LunTareg:
    driver=""
    url=""
    def __init__(self):
        self.url = "http://127.0.0.1:9580/sign-in.html"
        self.driver = Lunta.driver
        self.driver.get(self.url)

    def LTreg(self):
        time.sleep(2)
        self.driver.implicitly_wait(2)
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a").click()
        #注册成功
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("zhangs")
        self.driver.find_element(By.CSS_SELECTOR,"#nickname").send_keys("zhangs")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        time.sleep(2)
        Lunta.getScreenShot()
        self.driver.back()
        #登陆
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangs")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(2)
        # 查找头像是否登陆成功
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar")
        # 截屏登陆成功页面
        Lunta.getScreenShot()
        time.sleep(2)
        self.driver.back()

    def LTrefaii(self):
        time.sleep(2)
        self.driver.implicitly_wait(2)
        #点击注册
        self.driver.find_element(By.CSS_SELECTOR,"body > div > div > div > div:nth-child(1) > div > div.text-center.text-muted.mt-3 > a").click()
        # 注册失败(用户已存在)
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangs")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("zhangs")
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()

        #是否弹窗提示
        self.driver.find_element(By.CSS_SELECTOR,"body > div.jq-toast-wrap.bottom-right > div")
        Lunta.getScreenShot()

        # 注册失败(用户名为空)
        self.driver.find_element(By.CSS_SELECTOR, "#username").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()

        # 是否提示
        text=self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(2) > div").text
        assert text=="用户名不能为空"
        Lunta.getScreenShot()

        # 注册失败(昵称为空)
        self.driver.find_element(By.CSS_SELECTOR, "#username").send_keys("zhangs")
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()

        # 是否提示
        text = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(3) > div").text
        assert text == "昵称不能为空"
        Lunta.getScreenShot()

        # 注册失败(密码为空)
        self.driver.find_element(By.CSS_SELECTOR, "#nickname").send_keys("zhangs")
        self.driver.find_element(By.CSS_SELECTOR, "#password").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        time.sleep(2)
        # 是否提示
        text = self.driver.find_element(By.CSS_SELECTOR, "#signUpForm > div > div:nth-child(4) > div").text
        assert text == "密码不能为空"
        Lunta.getScreenShot()

        # 注册失败(确认密码错误)
        self.driver.find_element(By.CSS_SELECTOR, "#password").send_keys("1234")
        self.driver.find_element(By.CSS_SELECTOR, "#passwordRepeat").send_keys("12345")
        self.driver.find_element(By.CSS_SELECTOR, "#submit").click()
        text=self.driver.find_element(By.CSS_SELECTOR,"#signUpForm > div > div:nth-child(5) > div > div").text
        assert text=="请检查确认密码"


        #未点击同意
        self.driver.find_element(By.CSS_SELECTOR, "#policy").click()
        # 是否弹窗提示
        self.driver.find_element(By.CSS_SELECTOR, "body > div.jq-toast-wrap.bottom-right > div")
        Lunta.getScreenShot()
        self.driver.back()

